package com.huanling.main.keyconflictdealer;

import cn.hutool.core.map.MapUtil;

import java.util.List;
import java.util.Map;
import java.util.function.BiPredicate;
import java.util.function.Function;

/**
 * 处理key冲突的上下文
 *
 * @author guibo.sun
 * @since 16 七月 2021
 */
public class ConflictKeyContext {
    /**
     * key :用户提供的每条数据的 唯一标识
     * List
     * map |_key：列名
     * map |_value：对应列的值
     */
    private final Map<String, List<Map<String, Object>>> conflictKeyItems = MapUtil.newHashMap(false);


    private Function<Map<String, Object>, String> compareKeyGenerator;

    private BiPredicate<Map<String, Object>, Map<String, Object>> valueEqualsJudge;

    public ConflictKeyContext setCompareKeyGenerator(Function<Map<String, Object>, String> compareKeyGenerator) {
        this.compareKeyGenerator = compareKeyGenerator;
        return this;
    }

    public ConflictKeyContext setValueEqualsJudge(BiPredicate<Map<String, Object>, Map<String, Object>> valueEqualsJudge) {
        this.valueEqualsJudge = valueEqualsJudge;
        return this;
    }


    /**
     * 使用default权限，将功能保护在这个包内
     *
     * @return 返回 key 构建器
     */
    Function<Map<String, Object>, String> getCompareKeyGenerator() {
        return compareKeyGenerator;
    }

    /**
     * 使用default权限，将功能保护在这个包内
     *
     * @return 返回 equals 构架器
     */
    BiPredicate<Map<String, Object>, Map<String, Object>> getValueEqualsJudge() {
        return valueEqualsJudge;
    }

    /**
     * 使用default权限，将功能保护在这个包内
     *
     * @return
     */
    Map<String, List<Map<String, Object>>> getConflictKeyItems() {
        return conflictKeyItems;
    }
}
